/** @jsxImportSource @emotion/react */
import * as React from "react";
import { OriginalViewProps, } from "../../common/base";
import {EntranceSetup, config设备概况, config观测数据, config观测数据2, mesuZjText,} from "./orcBase";
import {createItem, } from "../../common/eHelper";
import {useRecordList} from "../../hook/useRecordList";
import {setupItemAreaRoute} from "./orcIspConfig";
import {EditStorageContext} from "../../StorageContext";
import {Text, useTheme} from "customize-easy-ui-component";
import {ItemInstrumentTable} from "../../common/Instrument";
import {FrontCover } from "../../mobilecr/editorIN";
import {ConclusionElvWtJj, } from "./editor";
import {SiteConditionSund,} from "../../elevator/sundryDj/editor";
import {GenCode} from "../../common/GenCode";
import {ActionMapItem} from "../../common/ActionMapItem";
import {config记录} from "./FormatOriginal";
import {MeasureCritMem} from "../../hook/useMeasure";
import {DeviceSurveyD} from "../../crane/editor";
import {DoorGap} from "./DoorGap";
import {WitnessSimple} from "../../elevator/stest/editor";
import {Pitspace, Pitspace2} from "./Pitspace";
import {Headspace, Headspace2, Headspace3} from "./Headspace";
import {Equilibrium} from "../../elevator/stest/Equilibrium";
import {items监控设施, MonitoringFacili} from "./MonitoringFacili";

//"pr":"*","ses":6  "r":3,"s":1  "big":"",
const defFrameM={
    'Rec3ClRep2Cl': `{ "mg":3, "dcl":"A","cl":"A",
         "sk":[{"no":"1.3.13","r":0},  {"big":"","r":6,"s":3}
    ] }`,
};
/*复杂1例子 "sk":[{"no":"1.3.5.1","r":0},{"r":4,"s":3}, {"big":"","no":"1.3.6","r":0},{"big":"","no":"1.3.7.1","r":0},0,0,0] }
正式报告recap标题例外>>3变成录入7个标题的：生成以后再人工修改；
A1.3.5.1限速器及电气安全装置
A1.3.5.2联动试验
缓冲器试验
A1.3.7.1试验方法
A1.3.7.2电气安全装
A1.3.7.3监测功能
A1.3.7.4试验
2例子 "sk":[{"no":"1.3.8.1","r":0},0,0,0, {"big":"","no":"1.3.11.1","r":2},0, {"big":"","no":"1.3.12.1","r":0},0,0 ] }
* */

export const tItems现场=[
    ['1、井道和机器空间内温度',{f:'T',
        N: <Text>1、机房或者机器设备间的空气温度保持在5℃～40℃之间；（单位：℃）</Text>},],
    ['2、供电电压波动范围',{f:'V',
        N: <Text>2、电源输入电压波动在额定电压值±7％的范围内；（单位：V）</Text>},],
    ['3、湿度不影响运行',{f:'s',
        N: <Text>3、湿度不影响设备正常运行，电器设备无凝露；</Text>},],
    ['4、进行必要的封闭防护',{f:'b',
        N: <Text>4、相关区域没有与电梯运行无关的物品和设备，进行了必要的封闭和防护，放置表明正在进行检验的警示标志；</Text>},],
    ['5、施工单位人员配合',{f:'P',
        N: <Text>5、施工单位安排了专业技术人员，配合实施现场检验。</Text>},],
];
//没有做 不合格表的
const recordPrintList =[
    createItem('Entrance', <EntranceSetup/>),
    createItem('FrontCover', <FrontCover/>),
    createItem('Instrument', <ItemInstrumentTable label={'一、主要检验仪器设备性能检查'} />),
    createItem('Survey', <DeviceSurveyD config={config设备概况} label={'二、设备概况'}/>),
    createItem('Item', null),
    createItem('Conclusion', <ConclusionElvWtJj startd nxtdesc='检验（检测）' label={'四、检验结论'}/>),
    createItem('Witness', <WitnessSimple label={'五、见证材料 六、备注'} titles={['五、见证材料','六、备注']}
                                         children={ [null,
                                 <React.Fragment key={12}>注：特殊情况，应在备注中说明检验人员所负责检验的项目编号。</React.Fragment>
                             ] }/>),
    createItem('Measure', <MeasureCritMem config={config观测数据}  label={'七、观测数据及测量结果记录(上)'}>
            {mesuZjText}
        </MeasureCritMem>),
    createItem('Measure2', <MeasureCritMem config={config观测数据2}  label={'七、观测数据及测量结果记录(下)'}>
            {mesuZjText}
        </MeasureCritMem>),
    createItem('Headspace', <Headspace label={'附录A-1:(适用曳引驱动非斜行电梯)当对重完全压缩缓冲器时，顶部空间数据'}/>),
    createItem('Headspace2', <Headspace2 label={'附录A-2:(适用曳引驱动斜行电梯)当对重完全压缩缓冲器时，顶部空间数据'}/>),
    createItem('Headspace3', <Headspace3 label={'附录A-3:(适用强制驱动电梯)当轿厢完全压缩上部缓冲器，顶部空间数据'}/>),
    createItem('Pitspace', <Pitspace label={'附录B-1：(适用非斜行电梯)当轿厢完全压缩缓冲器时，底坑空间数据的测量记录'}/>),
    createItem('Pitspace2', <Pitspace2 label={'附录B-2：(适用斜行电梯)当运载装置完全压缩缓冲器时，底坑空间数据的测量'}/>),
    createItem('Gap', <DoorGap label='附录C 电梯门地坎距离、门间隙、锁紧元件啮合深度等检验'/>),
    createItem('Equilibrium', <Equilibrium label={'附录D A1.3.2平衡系数试验'} config={[30,40,45,50,60]}>
                &nbsp; </Equilibrium>),
    createItem('SiteCondition', <SiteConditionSund config={tItems现场} label={'附录E：现场检验条件确认'}/>),
    createItem('MonitoringFacili', <MonitoringFacili config={items监控设施} label={'附录F 视频监控设施、远程监测装置、机房通风降温措施检查记录表'}/>),
];
if(process.env.REACT_APP_TEST==='true')  recordPrintList.splice(0,0,createItem('GenCode', <GenCode type='Rec3ClRep2Cl' frameMod={defFrameM}/>));


export const OriginalView=
  React.forwardRef((
    { action,  verId, repId='', rep,}
    :OriginalViewProps, ref
  ) => {
    const context =React.useContext(EditStorageContext);
    if(context == null)    throw new Error("EditStorageContext没有提供");
    const {storage, } =context;
    const theme = useTheme();
    const recordPrintListNow =React.useMemo(() => {
      let routeAreas=[] as any[];
      const impressionismAs =setupItemAreaRoute({rep, orc:storage, theme});
      let extendTags =Reflect.ownKeys(impressionismAs) as string[];
      const oldItCount=recordPrintList.length;
      let prevpos=0;
      for(let p=0; p<oldItCount; p++){
        if(extendTags.indexOf(recordPrintList[p].itemArea)>=0){     //需要展开 扩充的标签
            routeAreas=routeAreas.concat(recordPrintList.slice(prevpos,p));
            const itemConfigs= impressionismAs?.[recordPrintList[p].itemArea];
            let seq = 0;
            let moreItems = [] as any;
            itemConfigs.forEach((area, x) => {
              seq += 1;
              const rowHead =<ActionMapItem key={seq} alone={false} editAreasConf={itemConfigs}
                                                    index={x} sureD editIts={config记录} />;
              moreItems.push(createItem(area.tag, rowHead));
            });
            routeAreas=routeAreas.concat(moreItems);
            prevpos=p+1;
        }
      }
      routeAreas=routeAreas.concat(recordPrintList.slice(prevpos));
      return routeAreas;
    }, [verId, repId,rep, storage?._Oitems, theme]);

    const {list}=useRecordList(ref,rep,recordPrintListNow,action,verId);
    return <React.Fragment>
      {list}
        {/*      <Button  intent="primary"
                   onPress={(e) => { handleSubmit!();
                   }}
          >送打印转换器
          </Button>*/}
    </React.Fragment>;
  } );
